appPath = location.origin + "/Task/"
gitStatsData =[
    {
        name: "BUG"
        dir:"/gitStats/Bug"
        statsDir:"/gitStats/Bug"
    }
    ,{
        name:"tvuing"
        dir:""
        statsDir:""
    }
]

window.TS =
    appPath: appPath
    api: {}
    app: {}
    gitStatsData: gitStatsData

api = {}
window.TS.api = api

failHandler = (jqxhr)->
    alert jqxhr.message;

api.get = (relativeUrl, data)->
    $.get(appPath + relativeUrl, data)

#  $.ajax(appPath + relativeUrl, new AjaxOption("GET", data)).fail(failHandler);

api.post = (relativeUrl, data)->
    $.ajax(appPath + relativeUrl, new AjaxOption("POST", data)).fail(failHandler);

#TODO format
api.formatDate = (date)->
    date ?= new Date()
    year = date.getFullYear()
    month = date.getMonth() + 1
    month = if month.toString().length >= 2 then month else "0" + month
    day = date.getDate().toString()
    day = if day.length >= 2 then day else "0" + day
    hour = date.getHours().toString()
    hour = if hour.length >= 2 then hour else "0" + hour
    min = date.getMinutes().toString()
    min = if min.length >= 2 then min else "0" + min
    second = date.getSeconds().toString()
    second = if second.length >= 2 then second else "0" + second
    return "#{year}-#{month}-#{day} #{hour}:#{min}:#{second}"


$.fn.extend
    serializeObject: ->
        data = this.serializeArray();
        o = {}
        $.each data, ()->
            o[this.name] = this.value
        return o